/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package searchspads.util;

import java.awt.Color;
import java.awt.Component;
import java.io.Serializable;
import javax.swing.JCheckBox;
import javax.swing.JList;
import javax.swing.ListCellRenderer;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;

public class ComboCheckBoxRenderer extends JCheckBox implements ListCellRenderer, Serializable {
 
    protected static Border noFocusBorder;
 
    public ComboCheckBoxRenderer() {
        super();
        if (noFocusBorder == null) {
            noFocusBorder = new EmptyBorder(1, 1, 1, 1);
        }
        setOpaque(true);
        setBorder(noFocusBorder);
    }
 
    public Component getListCellRendererComponent(
            JList list,
            Object value,
            int index,
            boolean isSelected,
            boolean cellHasFocus) {
        setComponentOrientation(list.getComponentOrientation());
        if (isSelected) {
            setBackground(list.getSelectionBackground());
            setForeground(list.getSelectionForeground());
        } else {
            setBackground(list.getBackground());
            setForeground(list.getForeground());
        }
 
        if (value instanceof ComboCheckBoxEntry) {
            ComboCheckBoxEntry item = (ComboCheckBoxEntry) value;
            setSelected(item.getChecked());
            setToolTipText(item.getValue());
            setText(item.getValue());
        } else {
            setText("aaa");//(value == snull) ? "aaaa" : value.toString());
            //this.setVisible(true);
        }
 
        setEnabled(list.isEnabled());
        setFont(list.getFont());
        setBorder((cellHasFocus) ? UIManager.getBorder("List.focusCellHighlightBorder") : noFocusBorder);
 
        return this;
        //return 
    }
}